Page({
  data: {
    value: "",
    checked: false,
    listing: [],
    listed: []
  },
  Confirm(e) {
    // console.log(e.detail.value);
    var num = e.detail.value;
    var checked = this.data.checked;
    console.log(checked);
    var listing = this.data.listing;
    listing.push({
      num,
      checked
    })
    this.setData({
      listing,
      value: ""
    })
  },
  onClick(e) {
    var index = e.currentTarget.dataset;
    var listing = this.data.listing;
    listing.splice(index, 1);
    this.setData({
      listing
    })
  },
  onChanging(e) {
    console.log(e.detail);
    var {
      aid
    } = e.currentTarget.dataset
    // console.log(aid);
    var listing = this.data.listing;
    var listed = this.data.listed;
    listing.forEach((item, i) => {
      if (aid == i) {
        item.checked = e.detail;
      } else {
        item.checked = false;
      }
      if (item.checked) {
        var res = listing.splice(aid, 1);
        console.log(res);
        listed.push(...res)
      }
    })
    this.setData({
      listing,
      listed
    })
  },
  changed(e) {
    var {
      aid
    } = e.currentTarget.dataset
    // console.log(aid);
    var listed = this.data.listed
    var listing = this.data.listing
    listed.forEach((item, i) => {
      if (aid == i) {
        item.checked = false;
      }

      if (!item.checked) {
        var res = listed.splice(id, 1)
        listing.push(...res)
      }
    })
    this.setData({
      listed,
      listing
    })
  },
  onClicked(e) {
    var index = e.currentTarget.dataset;
    var listed = this.data.listed;
    listed.splice(index, 1);
    this.setData({
      listed
    })
  },
  onLoad: function (options) {},
})